/**
 *
 * @param table {Table}
 * @param auth {boolean} 接口是否需要鉴权
 * @param uninstall {boolean} 是否在生成代码时注释该方法，用于备用
 * @returns {string}
 */
const update = (table, auth = false, uninstall = false) => {
  const {
    comment,
    idType,
    existUpdateTimeColumn,
    author,
    names: {TabName}
  } = table
  const ordered = table.incrementAndGetOrdered()
  const authUserId = auth ? ', user.getId()' : ''
  return `// <-
    @PutMapping("/{encryptId}")
    //@PreAuthorize("hasAnyAuthority('ROLE_ADMIN', 'ROLE_ADMIN_TEST', '{}_update')")
    @ApiOperation(value = "${ordered}.修改${comment}", tags = {""})
    @ApiOperationSupport(
            order = ${ordered},
            author = "${author}",
            ignoreParameters = {
                    "${table.getInsertIncludeColumnNames()}"
            })
    @ResponseBody
    public Result<Void> update(
            @ApiIgnore @AuthenticationPrincipal final IUser user,
            @ApiParam(required = true, value = "加密id", example = "encryptId") @PathVariable final String encryptId,
            @RequestBody final ${TabName}UpdateDTO body
    ) {
        return new Result<Void>().call(() -> { // Controller 方法逻辑写在这里
            final AesApiId.AesId decrypt = AesApiId.decrypt(encryptId);
            ${existUpdateTimeColumn ? 'body.setUpdateTime(decrypt.getUpdateTime());' : ''}
            service.update(decrypt.get${idType}Id()${authUserId}, body);
        });
    }
`.split('\n')
    .map(row => (uninstall ? '//' : '') + row)
    .join('\n')
}
export const updateOpenInstall = table => update(table)
export const updateOpenUninstall = table => update(table, false, true)

export const updateAuthInstall = table => update(table, true, false)
export const updateAuthUninstall = table => update(table, true, true)
